import torch
import torch.nn as nn

#单层感知器
class ReviewClassifier(nn.Module):
    def __init__(self,num_features):
        super(ReviewClassifier,self).__init__()
        self.fc1=nn.Linear(in_features=num_features,
                           out_features=1)

    def forward(self,x_in,apply_sigmoid=False):
        y_out=self.fc1(x_in).squeeze()
        if apply_sigmoid:
            y_out=torch.sigmoid(y_out)
        return y_out

#多层感知器
class MultilayerPerceptron(nn.Module):
    def __init__(self,input_dim,hidden_dim,output_dim):
        super(MultilayerPerceptron,self).__init__()
        self.fc1=nn.Linear(input_dim,hidden_dim)
        self.fc2=nn.Linear(hidden_dim,output_dim)

    def forward(self,x_in,apply_softmax=False):
        relu=torch.nn.ReLU()
        dropout=torch.nn.Dropout
        intermediate=relu(self.fc1(x_in))
        output=self.fc2(dropout(intermediate))

        if apply_softmax:
            output=torch.softmax(output,dim=1)
        return output
